package com.kt.uokos.yimo.service.impl;

import com.github.pagehelper.PageHelper;
import com.kt.uokos.yimo.dao.AdminAddress;
import com.kt.uokos.yimo.example.AdminAddressExample;
import com.kt.uokos.yimo.mapper.AdminAddressMapper;
import com.kt.uokos.yimo.service.AdminAddressService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class AdminAddressServiceImpl implements AdminAddressService {

    @Resource
    private AdminAddressMapper adminAddressMapper;

    @Override
    public List<AdminAddress> querySelective(Integer userId, String name, Integer page, Integer limit, String sort, String order) {
        AdminAddressExample example = new AdminAddressExample();
        AdminAddressExample.Criteria criteria = example.createCriteria();

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (!StringUtils.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            example.setOrderByClause(sort + " " + order);
        }

        PageHelper.startPage(page, limit);
        return adminAddressMapper.selectByExample(example);
    }


}
